﻿using M_ApiResult;
using M_Process.API.Appliction.Command.ProductionProcessCommand;
using M_Process.Domain.DTO;
using M_Process.Domain;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using M_Process.API.Appliction.Command.ProcessTasksCommand;
using M_Process.API.Appliction.Command.ReportingCommand;

namespace M_Process.API.Controllers
{
    /// <summary>
    /// 工序任务控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcessTasksController : ControllerBase
    {
        /// <summary>
        /// Mediator
        /// </summary>
        protected readonly IMediator _mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_mediator">Mediator</param>
        public ProcessTasksController(IMediator _mediator)
        {
            this._mediator = _mediator;
        }

        /// <summary>
        /// 新增工序任务信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreadProcessTasks(CreateProcessTasksCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 工序任务列表分页展示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ProcessTasksDto<ProcessTasks>>> ShowShowProcessTasksList([FromQuery] ShowProcessTasksCommand command)
        {
            ApiResult<ProcessTasksDto<ProcessTasks>> result = new ApiResult<ProcessTasksDto<ProcessTasks>>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 删除工序任务信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteProcessTasks(DeletedProcessTasksCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await _mediator.Send(command);

            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 批量删除工序
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> BatchDeletedProcessTasks(BatchDeletedProcessTasksCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await _mediator.Send(command);

            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 反填工序任务信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ProcessTasks>> ReverseFillingProcessTasks([FromQuery] ReverseFillingProcessTasksCommand command)
        {
            ApiResult<ProcessTasks> result = new ApiResult<ProcessTasks>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 修改工序任务信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateProcessTasks(UpdateProcessTasksCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 修改工序任务状态
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateProcessTasksStatus(UpdateStatusCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 新增报工任务信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreadReporting(AddReportingCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 报工列表分页展示(ById)
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ReportingDto<ReportingProcessTaskDto>>> ShowReportingListById([FromQuery] ShowReportingCommand command)
        {
            ApiResult<ReportingDto<ReportingProcessTaskDto>> result = new ApiResult<ReportingDto<ReportingProcessTaskDto>>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }


        /// <summary>
        /// 报工列表分页展示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ReportingDto<ReportingProcessTaskDto>>> ShowAllReportingList([FromQuery] ShowReportingListCommand command)
        {
            ApiResult<ReportingDto<ReportingProcessTaskDto>> result = new ApiResult<ReportingDto<ReportingProcessTaskDto>>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 反填报工任务信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ReportingProcessTaskDto>> ReverseFillingReporting([FromQuery] ReverseReportingCommand command)
        {
            ApiResult<ReportingProcessTaskDto> result = new ApiResult<ReportingProcessTaskDto>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }


    }
}
